import unittest,time
from selenium import webdriver
from selenium.webdriver.common.by import By
# ddt数据驱动测试工具 / ddt,file_data测试多种
from ddt import ddt,file_data


@ddt
class A3mall(unittest.TestCase):
    def setUp(self) -> None:
        self.driver = webdriver.Edge()
        self.driver.maximize_window()
        self.driver.get('http://10.59.9.14:7003/')
        self.driver.implicitly_wait(10)

    # 通过@file_data('aaa.json')从json 文件读取多组用户名和密码
    @file_data('aaa.json')
    def test_login(self,username,password):
        # 登录
        self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').click()
        # 断言1：断言文本：会员登陆
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[4]/div/div[1]/div[1]/span[1]').text
        print("文本断言1，会员登陆:", dy1)
        time.sleep(3)
        # 用户名  密码
        self.driver.find_element(By.NAME, 'username').send_keys(username)
        self.driver.find_element(By.NAME, 'password').send_keys(password)
        time.sleep(8)
        # 登录按钮
        self.driver.find_element(By.XPATH, '//*[@id="theForm"]/div[5]/a').click()
        # 断言2：断言文本：欢迎回来，13811033962
        dy2 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div/div[2]/ul/li[1]/a').text
        print("文本断言2，欢迎回来，13811033962:", dy2)
        time.sleep(2)
        # 断言3：断言文本：账户余额：¥ 988389770.25  中的 988389770.25
        dy3 = self.driver.find_element(By.XPATH, '/html/body/div[5]/div[2]/div[1]/div[2]/div[2]/ul/li[4]').text
        dy31 = dy3.replace('¥ ', '')
        print("文本断言3，账户余额:", dy31)
        time.sleep(2)

    def tearDown(self) -> None:
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()